package com.inbound;

import com.NettyServer;
import io.netty.channel.ChannelHandler;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;

public class ClientDisconnectHandler extends ChannelInboundHandlerAdapter{
	
    @Override
    public void channelInactive(ChannelHandlerContext ctx){
    	if( NettyServer.GPRS_MAP.containsKey( ctx.channel().attr(NettyServer.GPRS).get().getId() ) ){
           if(ctx.channel().id().asLongText()==
        		   NettyServer.GPRS_MAP.get(ctx.channel().attr(NettyServer.GPRS).get().getId())
        		   .getChannelHandlerContext().channel().id().asLongText())
    	     ctx.channel().attr(NettyServer.GPRS).get().offline();
        }
    }


    @Override
    public void channelRead(ChannelHandlerContext ctx, Object msg){

    }

    @Override
    public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause)
            throws Exception {
        cause.printStackTrace();
        ctx.close();
    }


}
